using System;
using System.Collections.Generic;
using System.Text;

using libsecondlife;
using Feathertail;

namespace NestBox.Finance
{
    class Pay : Command
    {
        SecondLife _Client;

        #region Command Members

        public void Setup(FeathertailClient Client)
        {
            _Client = Client;
        }

        public string HandleInput(string[] CmdLine)
        {
            if (CmdLine.Length < 3)
            {
                return GetHelpText();
            }

            LLUUID AgentID;
            if (LLUUID.TryParse(CmdLine[1], out AgentID) == false)
            {
                return "Invalid AgentID: " + CmdLine[1] + Environment.NewLine + GetHelpText();
            }

            int Amount;
            if (Int32.TryParse(CmdLine[2], out Amount) == false)
            {
                return "Invalid L$: " + CmdLine[2] + Environment.NewLine + GetHelpText();
            }

            string Description = "";
            if( CmdLine.Length == 4 )
            {
                Description = CmdLine[3];
            }

            _Client.Self.GiveMoney(AgentID, Amount, Description);

            return "Gave L$" + Amount + " to " + AgentID.ToStringHyphenated() + " with description '" + Description + "'";

        }

        public string[] GetCommandStrings()
        {
            return new string[] { "pay" };
        }

        public string GetSummaryText()
        {
            return "Pay L$ to someone";
        }

        public string GetHelpText()
        {
            return "Usage: pay <AgentID> <L$> [Description]";
        }

        #endregion
    }
}
